<?php
/**
 * Contains and manages the Elastic theme layout
 * 
 * PHP4 Compatibility
 *   - Extending Object makes __construct() the constructor.
 * 
 * @package default
 * @author Daryl Koopersmith
 **/

class Layout extends Object {
	
	var $blocks = array();
	var $context;
	
	
	function __construct($json) {
		if( is_array($json) ) {
			
		}
	}
	

	/**
	 * Retrive the context of the queried template.
	 * Credit: Chris Jean & Ptah Dunbar
	 *
	 * @global array $this->context Returns value if already set.
	 * @return array $this->context
	 */


	function get_context() {
		global $wp_query, $this->context;

		if ( isset( $this->context ) )
			return $this->context;

		$this->context = array( 'abstract' => null, 'general' => null, 'specific' => null );
		$id = $wp_query->get_queried_object_id();

		if ( is_front_page() )
			$this->context['general'] = 'home';
		else if ( is_singular() ) {
			$this->context['abstract'] = 'singular';

			if ( is_attachment() ) {
				$this->context['general'] = 'attachment';
				$this->context['specific'] = 'attachment-'. $id;
			}
			else if ( is_single() ) {
				$this->context['general'] = 'single';
				$this->context['specific'] = 'single-'. $id;
			}
			else if ( is_page() ) {
				$this->context['general'] = 'page';
				$this->context['specific'] = 'page-'. $id;
			}
		}
		else if ( is_archive() ) {
			$this->context['abstract'] = 'archive';

			if ( is_category() ) {
				$this->context['general'] = 'category';
				$this->context['specific'] = 'category-'. $id;
			}
			else if ( is_tag() ) {
				$this->context['general'] = 'tag';
				$this->context['specific'] = 'tag-'. $id;
			}
			else if ( is_date() ) {
				$this->context['general'] = 'date';

				if ( is_month() )
					$this->context['specific'] = 'month-'. $id;
				else if ( is_year() )
					$this->context['specific'] = 'year-'. $id;
				else if ( is_day() )
					$this->context['specific'] = 'day-'. $id;
				else if ( is_time() )
					$this->context['specific'] = 'time-' . $id;
			}
			else if ( is_author() ) {
				$this->context['general'] = 'author';
				$this->context['specific'] = 'author-'. $id;
			}
			else if ( is_tax() ) {
				$this->context['general'] = 'tax';
				$this->context['specific'] = 'tax-'. $id;
			}
		}
		else if ( is_search() )
			$this->context['general'] = 'search';
		else if ( is_404() )
			$this->context['general'] = 'error404';


		return $this->context;
	}
}

?>